// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// A [author] rhyme_lph
// h [email]  rhymelph@gmail.com
// K [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_spaces.dart';
import 'package:finance_app/src/provider/invite_team/manage_role_access_provider.dart';
import 'package:finance_app/src/router_gen/router_meta.dart';
import 'package:finance_app/src/widgets/button/normal_popup_button.dart';
import 'package:finance_app/src/widgets/common_app_bar.dart';
import 'package:finance_app/src/widgets/form/add_form.dart';
import 'package:finance_app/src/widgets/list_item/setting_list_item.dart';
import 'package:flutter/material.dart';

@RouterMeta(paramName: "manageRoleAccessPage")
class ManageRoleAccessPage extends StatefulWidget {
  const ManageRoleAccessPage({Key key}) : super(key: key);

  @override
  _ManageRoleAccessPageState createState() => _ManageRoleAccessPageState();
}

class _ManageRoleAccessPageState extends State<ManageRoleAccessPage>
    with PagePresenter<ManageRoleAccessPage, ManageRoleAccessProvider> {
  @override
  void initState() {
    super.initState();
  }

  @override
  PreferredSizeWidget get appBar =>
      getDefaultAppBar(title: S.current.manage_role_access, actions: [
        NormalMorePopupButton(
          onSelect: provider.onSelectMenu,
          menuList: provider.menuList,
        ),
      ]);

  @override
  Widget get buildEmptyWidget => ColoredBox(
        color: Colors.white,
        child: Column(
          children: [
            AppSpaces.h20,
            Expanded(child: super.buildEmptyWidget),
          ],
        ),
      );

  @override
  Widget get buildWidget => ColoredBox(
        color: Colors.white,
        child: ListView(
          children: [
            ...provider.data.map((e) => SettingListItem(
                  title: e.name,
                  onTap: () => provider.onNavRolePage(e),
                )),
            AppSpaces.h20,
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                AddForm(
                  title: S.current.add_role,
                  topPadding: 0,
                  onTap: () => provider.onNavRolePage(null),
                ),
                AddForm(
                  title: S.current.duplicate_role,
                  topPadding: 0,
                  leftPadding: 0,
                  onTap: () => provider.onDuplicateRole(),
                ),
              ],
            ),
          ],
        ),
      );
}
